{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--BOOK_INFORMATION-->\n",
    "<img align=\"left\" style=\"padding-right:10px;\" src=\"figures/PHydro-cover-small.png\">\n",
    "*This is the Jupyter notebook version of the [Python in Hydrology](http://www.greenteapress.com/pythonhydro/pythonhydro.html) by Sat Kumar Tomer.*\n",
    "*Source code is available at [code.google.com](https://code.google.com/archive/p/python-in-hydrology/source).*\n",
    "\n",
    "*The book is available under the [GNU Free Documentation License](http://www.gnu.org/copyleft/fdl.html). If you have comments, corrections or suggestions, please send email to satkumartomer@gmail.com.*"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<!--NAVIGATION-->\n",
    "< [10. Advance Statistics](10.00-Advance-Statistics.ipynb) | [Contents](Index.ipynb) | [Multivariate Distribution](10.02-Multivariate-Distribution.ipynb)>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 10.1 copula\n",
    "\n",
    "Copulas用于描述两个随机变量的相关性。Copula意味着耦合两个CDF。让我们生成两个随机变量:一个具有正态分布，另一个是正态分布和均匀分布的组合。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from matplotlib.ticker import NullFormatter\n",
    "\n",
    "# synthetic data\n",
    "x = np.random.randn(1000)\n",
    "y = np.random.randn(1000)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "首先我们想要通过使用散点图看我们的数据是如何关联的，我们也想要查看x和y是如何分布的。我们可以在三个独立的图或使用子图(subplot)来做这个。在本例中，我们通过为三个图指定不同的坐标轴将来在一个图中尝试此操作。我们从定义三个图的坐标范围开始。对`axis`的输入是左下角的x和y，图形的宽度和高度。在下面的示例中，我们以类似的方式指定轴，以便使图正确对齐。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true,
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "plt.clf()\n",
    "axScatter = plt.axes([0.1, 0.1, 0.5, 0.5])\n",
    "axHistx = plt.axes([0.1, 0.65, 0.5, 0.3])\n",
    "axHisty = plt.axes([0.65, 0.1, 0.3, 0.5])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在，我们使用这个轴来绘制图形。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAZsAAAEXCAYAAAB76ulbAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3W2MXNWZJ/D/0+XCVJus245bxBSG9qwsEF4n7qEFlrza\nWSCDyfDWC6sAgRFRIqGVMhJmImfaA4pxNixmrSV82BmtkBItEt5gMiaNGScyBHs0GlYmtNNtjME9\ncQLYFE7oLLQDuLCru5/9UPe2b1Xdt6q6p+69df8/yXJ3VfWtU2/3qXPOc54jqgoiIiKTeuJuABER\ndT8GGyIiMo7BhoiIjGOwISIi4xhsiIjIOAYbIiIyjsGGiIiMY7AhIiLjGGyIiMi4BXE3AACWLVum\nAwMDcTeDqCsdPHjwD6raH3c7KNsSEWwGBgYwNjYWdzOIupKIvBt3G4g4jEZERMYx2BARkXGJGEaj\ndBkY2RPp8d7ZdmOkxyOi5GHPhoiIjGOwISIi4xhsiIjIOM7ZZETU8yxERM1gz4aIiIxjsCEiIuMY\nbIiIyDgGGyIiMo7BhoiIjGOwISIi4xhsiIjIOAYbIiIyjsGGiIiMCww2IrJCRPaLyJsickRE7rcu\nXyoiL4nIr63/lzj+ZrOIHBORSRHZYPIBEBFR8oXp2cwA+LaqXgFgHYBvicgVAEYAvKyqqwC8bP0O\n67o7AawGcAOAvxeRnInGExFROgQGG1U9qaq/sn7+GMBbAIoAbgXwlHWzpwAMWz/fCuAZVT2jqm8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Kg\n0jAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x9915710>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# the plots\n",
    "axScatter.scatter(x, y)\n",
    "axHistx.hist(x)\n",
    "axHisty.hist(y, orientation='horizontal')\n",
    "\n",
    "# set the limit of histogram plots\n",
    "axHistx.set_xlim(axScatter.get_xlim())\n",
    "axHisty.set_ylim(axScatter.get_ylim())\n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center>图10.1:散点图与边缘直方图</center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "图10.1显示了结果图。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在让我们使用copula模拟数据集合。我已经编写了一个库，`ambhas.copula`(译者注:该库目前只支持python2.7版本)来处理copulas。这个库内有三个copula(Frank,Clayton和Gumbel)。首先我们导入库，然后初始化这个类。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "third:10001000\n"
     ]
    }
   ],
   "source": [
    "from ambhas.copula import Copula\n",
    "foo = Copula(x, y,'frank')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以通过`tau`和`theta`属性分别得到Kendall的tau的值和Frank的参数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.00867667667668\n"
     ]
    }
   ],
   "source": [
    "print(foo.tau)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.078125\n"
     ]
    }
   ],
   "source": [
    "print(foo.theta)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们可以使用Frank copula生成集合。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "ename": "AttributeError",
     "evalue": "'module' object has no attribute 'cpdf'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAttributeError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-21-4d6578fc1f21>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mx1\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfoo\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mgenerate_xy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mC:\\Users\\laihetao\\DebugUself\\6.python learning\\Python-in-Hydrology\\ambhas\\copula.py\u001b[0m in \u001b[0;36mgenerate_xy\u001b[1;34m(self, n)\u001b[0m\n\u001b[0;32m    183\u001b[0m         \u001b[1;31m# estimate inverse cdf of x andy\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    184\u001b[0m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_inverse_cdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 185\u001b[1;33m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    186\u001b[0m         \u001b[1;31m# estimate X1 and Y1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    187\u001b[0m         \u001b[0mX1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_inv_cdf_x\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mU\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mC:\\Users\\laihetao\\DebugUself\\6.python learning\\Python-in-Hydrology\\ambhas\\copula.py\u001b[0m in \u001b[0;36m_inverse_cdf\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m    205\u001b[0m         \"\"\"\n\u001b[0;32m    206\u001b[0m         \u001b[0mx2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mst\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcpdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mX\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkernel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'Epanechnikov'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 207\u001b[1;33m         \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_inv_cdf_x\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0minterp1d\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mx1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    208\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    209\u001b[0m         \u001b[0my2\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mst\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcpdf\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mY\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkernel\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'Epanechnikov'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mn\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m100\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAttributeError\u001b[0m: 'module' object has no attribute 'cpdf'"
     ]
    }
   ],
   "source": [
    "x1,y1 = foo.generate_xy()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "\n",
    "这个不是官方的statistics库，而是。。。http://bonsai.hgc.jp/~mdehoon/software/python/Statistics/\n",
    "\n",
    "http://bonsai.hgc.jp/~mdehoon/software/python/"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "现在，我们可以用原始数据绘制模拟数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "plt.scatter(x1,y1,color='g')\n",
    "plt.scatter(x,y,color='r')\n",
    "plt.xlabel('x')\n",
    "plt.ylabel('y')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
